package com.ruoyi.travel.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.travel.domain.TravelBanner;
import com.ruoyi.travel.service.ITravelBannerService;

/**
 * 轮播图Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/travel/banner")
public class TravelBannerController extends BaseController
{
    @Autowired
    private ITravelBannerService travelBannerService;

    /**
     * 查询轮播图列表
     */
    @RequiresPermissions("travel:banner:list")
    @GetMapping("/list")
    public TableDataInfo list(TravelBanner travelBanner)
    {
        startPage();
        List<TravelBanner> list = travelBannerService.selectTravelBannerList(travelBanner);
        return getDataTable(list);
    }

    /**
     * 小程序查询轮播图列表（无需权限）
     */
    @GetMapping("/app/list")
    public AjaxResult appList()
    {
        TravelBanner banner = new TravelBanner();
        banner.setStatus("0"); // 只查询正常状态
        List<TravelBanner> list = travelBannerService.selectTravelBannerList(banner);
        return success(list);
    }

    /**
     * 获取轮播图详细信息
     */
    @RequiresPermissions("travel:banner:query")
    @GetMapping(value = "/{bannerId}")
    public AjaxResult getInfo(@PathVariable("bannerId") Long bannerId)
    {
        return success(travelBannerService.selectTravelBannerById(bannerId));
    }

    /**
     * 新增轮播图
     */
    @RequiresPermissions("travel:banner:add")
    @Log(title = "轮播图", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TravelBanner travelBanner)
    {
        travelBanner.setCreateBy(SecurityUtils.getUsername());
        return toAjax(travelBannerService.insertTravelBanner(travelBanner));
    }

    /**
     * 修改轮播图
     */
    @RequiresPermissions("travel:banner:edit")
    @Log(title = "轮播图", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TravelBanner travelBanner)
    {
        travelBanner.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(travelBannerService.updateTravelBanner(travelBanner));
    }

    /**
     * 删除轮播图
     */
    @RequiresPermissions("travel:banner:remove")
    @Log(title = "轮播图", businessType = BusinessType.DELETE)
    @DeleteMapping("/{bannerIds}")
    public AjaxResult remove(@PathVariable Long[] bannerIds)
    {
        return toAjax(travelBannerService.deleteTravelBannerByIds(bannerIds));
    }
}

